package 方法的抽象和逐步求精;

public class Exercise5_9英尺和米之间的转换 {

	/**
	 * 英尺转米
	 * @param foot
	 * @return
	 */
	public static double footToMeter(double foot){
		return foot * 0.305;
	}
	
	/**
	 * 米转英尺
	 * @param meter
	 * @return
	 */
	public static double meterToFoot(double meter){
		return meter / 0.305;
	}
	/**
	 * 保留小数点后
	 * @return
	 */
	public static double retainDecimal(double longDouble,int n){
		int[] several = {10,100,1000,10000};
		return (double)Math.round(longDouble * several[n-1])  / several[n-1];
	}
	
	public static void printTable(){
		System.out.println("英尺\t\t米\t\t米\t\t英尺");
		double meter = 20;
		double foot = 1;
		for (int i = 0; i < 10;meter+=5,foot++, i++) {
			System.out.println(foot+"\t\t"+footToMeter(foot)+"\t\t"+meter+"\t\t"+retainDecimal(meterToFoot(meter),3));
		}
	}
	
	public static void main(String[] args) {
		printTable();
	}
}
